// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    traceUser: true,
    env: 'aaa111-9gh9fp5ieac4de5d'
})

const db = cloud.database()

// 云函数入口函数
exports.main = async (event, context) => {
    //删除文章
    try {
        await db.collection('postinfo').where({
            _id: event.artId
        }).remove()
        //删除点赞收藏
        await db.collection('userHeart').where({
            artId: event.artId
        }).remove()
        await db.collection('userStar').where({
            artId: event.artId
        }).remove()
        //删除阅读记录
        await db.collection('postReadHistory').where({
            artId: event.artId
        }).remove()
        return true
    } catch (e) {
        console.error(e)
    }
}